<% content_for :title do %>
<%= :event_list_title.l%> - <%= :"event_state_#{@state}".l %>
<% end %>

<% content_for :tabs do %>

<%= form_tag update_availability_events_url, :class => 'list_form', :id => 'update_availability' %>
<%= hidden_field_tag 'state', @state %>
<ul id="tabs">
<% Event.all_states(current_user).each do |key|-%>
  <li<%= key == @state ? ' class="active"' : '' %>><%= link_to(:"event_state_#{key}".l + " (#{number_of_events_in_state key})", :state => key) %></li>
<% end -%>
</ul>
<ul id="optionbar">
  <% if logged_in_as_manager? -%>
  <% if @state == 'new' %>
  <li><%= link_to :menu_new_event.l, new_resource_url %></li>
  <% end %>
  <li><%= link_to :change_state_button.l, choose_for_state_change_events_url(:state => @state), {:method => 'get'} %></li>
  <% end -%>
  <% if @state == 'cfw' %>
  <li><%= submit_tag :update_availability.l %></li>
  <% end %>
  <div class="clearing"></div>
</ul>
<% end %>

<div class="clearing">&nbsp;</div>

<% if %w(cfw assigned).member? @state %>
<div id="help">  <h3><%= :help.l %></h3><%= :"#{@state}_help".l %></div>
<% end %>

<table class="list">
  <thead>
    <tr>
      <th><%= link_to :event_name.l, params.merge(:sort => :name) %></th>
      <th><%= link_to :event_start_date.l, params.merge(:sort => :start_date) %></th>
      <th><%= link_to :event_end_date.l, params.merge(:sort => :end_date) %></th>
      <% if @state == 'cfw' %>
      <th><%= :availability.l %></th>
      <% end %>
      <% if logged_in_as_manager? -%>
      <% if %w(cfw tba assigned).member? @state %>
      <th><%= link_to :volunteer_count.l, params.merge(:sort => :volunteer_count) %></th>
      <% end %>
      <% if %w(tba assigned).member? @state %>
      <th><%= link_to :assigned_count.l, params.merge(:sort => :assigned_count) %></th>
      <% end %>
      <th>&nbsp;</th>
      <% end -%>
    </tr>
  </thead>
  <tbody>
<% resources.each do |event| -%>
    <tr>
      <td><%= link_to event.name, resource_url(event) %></td>
      <td><%= event.start_date.localize %></td>
      <td><%= event.end_date.localize %></td><% attending = current_user.can_attend? event %>
      <% if event.state == 'cfw' %>
      <td class="radio_container">
        <%= select_tag "attendances[#{event.id}]", options_for_select(
              [[:attend_first.l, 3], [:attend_second.l, 2], [:attend_maybe.l, 1], [:attend_no.l, 0]],
            attending || 0) %>
      </td>
      <% end %>
      <% if logged_in_as_manager? -%>
      <% if %w(cfw tba assigned).member? @state %>
      <td class="number"><%= event.volunteer_count %></td>
      <% end %>
      <% if %w(tba assigned).member? @state %>
      <td class="number"><%= event.assigned_count %></td>
      <% end %>
      <td>
        (<%= link_to(:delete.l, resource_url(event), :method => 'delete', :rel => 'nofollow', :confirm => :event_delete_confirmation.localize_with_args(:event => event.name)) %>)
      </td>
      <% end -%>
    </tr>
<% end -%>
  </tbody>
</table>
</form>

<% content_for :scripts do -%>
var noticeRaised = false;
$(document).ready(function() {
  $("select").change(
    function() {
      if (!noticeRaised) {
        if ($("#notice").size() == 0) {
          $("#optionbar").after("<p id=\"notice\"></p>");
        }
        $("#notice").text('<%= :taint_warning_above.l %>');
        noticeRaised = true;
      }
    }
  );
});
<% end %>
